/* model */
import { TriggerFlowData, TriggerEdge, NodeTypeEnum, ProcessNode, TriggerNode, ProcessEdge } from "@src/modules/trigger/model"
/* utils */
import { uuid } from "@src/util/lang/string";
import _, { isNull } from 'lodash'


export const mockData = [
    {
        "id": "start-node",
        "type": "start-node",
        "title": "节点4-1",
        "content": "执行任务4-1",
        "children": [
            {
                "id": "start-node",
                "type": "node",
                "title": "节点4-1",
                "content": "执行任务4-1",
                "children": [
                    {
                        "id": "start-node",
                        "type": "condition",
                        "title": "节点4-1",
                        "content": "执行任务4-1",
                        "children": [
                            {
                                "id": "start-node",
                                "type": "node",
                                "title": "条件-1",
                                "content": "执行任务4-1",
                                "children": [],
                                "options":  {}
                            },
                            {
                                "id": "start-node",
                                "type": "node",
                                "title": "条件-2",
                                "content": "执行任务4-1",
                                "children": [],
                                "options":  {}
                            }
                        ],
                        "options":  {}
                    }
                ],
                "options":  {}
            }
        ],
        "options":  {}
    },
    {
        "id": "end-node",
        "type": "end-node",
        "title": "节点4-1",
        "content": "执行任务4-1",
        "children": [],
        "options":  {}
    }
]
export const mockData2 = [{
  "type": "nodeStart",
  "name": "",
  "content": "",
  "children": [
      {
          "type": "node",
          "name": "",
          "content": "",
          "children": [
              {
                  "type": "node",
                  "name": "",
                  "content": "",
                  "children": [
                      {
                          "type": "node",
                          "name": "",
                          "content": "",
                          "children": [],
                          "uniqueId": "99810",
                          "id": "99810",
                          "options": {
                              "apiId": "",
                              "apiAction": "insert/update/delete/message/code",
                              "moduleId": "",
                              "appId": "",
                              "appName": "工单中心99810",
                              "appLogo": "",
                              "selectObjName": "维保工单/编辑工单",
                              "fieldOptions": {}
                          },
                          "parentNode": {
                              "type": "node",
                              "name": "",
                              "content": "",
                              "children": [],
                              "uniqueId": "998",
                              "id": "998",
                              "options": {
                                  "apiId": "",
                                  "apiAction": "insert/update/delete/message/code",
                                  "moduleId": "",
                                  "appId": "",
                                  "appName": "工单中心",
                                  "appLogo": "",
                                  "selectObjName": "维保工单/编辑工单",
                                  "fieldOptions": {}
                              },
                              "parentNode": null
                          }
                      }
                  ],
                  "uniqueId": "998",
                  "id": "998",
                  "options": {
                      "apiId": "",
                      "apiAction": "insert/update/delete/message/code",
                      "moduleId": "",
                      "appId": "",
                      "appName": "工单中心",
                      "appLogo": "",
                      "selectObjName": "维保工单/编辑工单",
                      "fieldOptions": {}
                  },
                  "parentNode": {
                      "type": "node",
                      "name": "",
                      "content": "",
                      "children": [],
                      "uniqueId": "12232",
                      "id": "12232",
                      "options": {
                          "apiId": "",
                          "apiAction": "insert/update/delete/message/code",
                          "moduleId": "",
                          "appId": "",
                          "appName": "工单中心",
                          "appLogo": "",
                          "selectObjName": "维保工单/编辑工单",
                          "fieldOptions": {}
                      },
                      "parentNode": null
                  }
              }
          ],
          "uniqueId": "12232",
          "id": "12232",
          "options": {
              "apiId": "",
              "apiAction": "insert/update/delete/message/code",
              "moduleId": "",
              "appId": "",
              "appName": "工单中心",
              "appLogo": "",
              "selectObjName": "维保工单/编辑工单",
              "fieldOptions": {}
          },
          "parentNode": {
              "type": "nodeStart",
              "name": "",
              "content": "",
              "children": [],
              "uniqueId": "1222",
              "id": "1222",
              "options": {
                  "apiId": "567",
                  "apiAction": "select",
                  "moduleId": "123",
                  "appId": "987",
                  "appName": "工单中心",
                  "appLogo": "",
                  "selectObjName": "维保工单/工单信息",
                  "executeWay": {
                      "way": "event",
                      "wayName": "事件触发",
                      "options": {}
                  }
              },
              "parentNode": null
          }
      }
  ],
  "uniqueId": "1222",
  "id": "1222",
  "options": {
      "apiId": "567",
      "apiAction": "select",
      "moduleId": "123",
      "appId": "987",
      "appName": "工单中心",
      "appLogo": "",
      "selectObjName": "维保工单/工单信息",
      "executeWay": {
          "way": "event",
          "wayName": "事件触发",
          "options": {}
      }
  },
  "parentNode": null
}]

export const serverData = {
    "id": "触发器id",
    "name": "触发器名称",
    "executeWay": {
      "way": 'event',
      "wayName": "事件触发",
      "options": {}
    },
    "startNode": {
      "id": "1222",
      "uniqueId": "1222",
      "options": {
        "apiId": "567",
        "apiAction": "select",
        "moduleId": "123",
        "appId": "987",
        "appName": "工单中心",
        "appLogo": "",
        "selectObjName": "维保工单/工单信息"
      }
    },
    "nodeList": [
      {
        "id": "12232",
        "uniqueId": "12232",
        "options": {
          "apiId": "",
          "apiAction": "insert/update/delete/message/code",
          "moduleId": "",
          "appId": "",
          "appName": "工单中心",
          "appLogo": "",
          "selectObjName": "维保工单/编辑工单",
          "fieldOptions": {}
        }
      },
      {
        "id": "998",
        "uniqueId": "998",
        "options": {
          "apiId": "",
          "apiAction": "insert/update/delete/message/code",
          "moduleId": "",
          "appId": "",
          "appName": "工单中心",
          "appLogo": "",
          "selectObjName": "维保工单/编辑工单",
          "fieldOptions": {}
        }
      },
      {
        "id": "99810",
        "uniqueId": "99810",
        "options": {
          "apiId": "",
          "apiAction": "insert/update/delete/message/code",
          "moduleId": "",
          "appId": "",
          "appName": "工单中心99810",
          "appLogo": "",
          "selectObjName": "维保工单/编辑工单",
          "fieldOptions": {}
        }
      }
    ],
    "lineList": [
      {
        "id": '456',
        "name": "条件名称",
        "from": "1222",
        "to": "12232",
        "options": {
          "convertType": "mapping/code",
          "convertCode": "",
          "formList": "jinkai",
          "conditionList": [
            [
              {
                "value": [
                  "15899999999"
                ],
                "operate": "NOT_EQ",
                "toEnName": "fbd0a248-f089-4664-8063-a41c22a5eb5f:field_4CXOdB9URxML7fYz",
                "valueType": 1
              },
              {
                "value": [
                  "15800000000"
                ],
                "operate": "NOT_EQ",
                "toEnName": "fbd0a248-f089-4664-8063-a41c22a5eb5f:field_4CXOdB9URxML7fYz",
                "valueType": 1
              }
            ]
          ]
        }
      },
      {
        "id": '45611110',
        "name": "条件名称x",
        "from": "12232",
        "to": "99810",
        "options": {
          "convertType": "mapping/code",
          "convertCode": "",
          "conditionList": [
            [
              {
                "value": [
                  "15899999999"
                ],
                "operate": "NOT_EQ",
                "toEnName": "fbd0a248-f089-4664-8063-a41c22a5eb5f:field_4CXOdB9URxML7fYz",
                "valueType": 1
              },
              {
                "value": [
                  "15800000000"
                ],
                "operate": "NOT_EQ",
                "toEnName": "fbd0a248-f089-4664-8063-a41c22a5eb5f:field_4CXOdB9URxML7fYz",
                "valueType": 1
              }
            ]
          ]
        }
      },
      {
        "id": '45699',
        "name": "条件名称",
        "from": "1222",
        "to": "998",
        "options": {
          "convertType": "mapping/code1",
          "convertCode": "",
          "conditionList": [
            [
              {
                "value": [
                  "15899999999"
                ],
                "operate": "NOT_EQ",
                "toEnName": "fbd0a248-f089-4664-8063-a41c22a5eb5f:field_4CXOdB9URxML7fYz",
                "valueType": 1
              },
              {
                "value": [
                  "15800000000"
                ],
                "operate": "NOT_EQ",
                "toEnName": "fbd0a248-f089-4664-8063-a41c22a5eb5f:field_4CXOdB9URxML7fYz",
                "valueType": 1
              }
            ]
          ]
        }
      }
    ]
} as unknown as TriggerFlowData


export const serverData1 = {
  "id": "触发器id",
  "name": "触发器名称",
  "executeWay": {
    "way": 'event',
    "wayName": "事件触发",
    "options": {}
  },
  "startNode": {
    "id": "1222",
    "uniqueId": "1222",
    "options": {
      "apiId": "567",
      "apiAction": "select",
      "moduleId": "123",
      "appId": "987",
      "appName": "工单中心",
      "appLogo": "",
      "selectObjName": "维保工单/工单信息"
    }
  },
  "nodeList": [
    {
      "id": "12232",
      "uniqueId": "12232",
      "options": {
        "apiId": "",
        "apiAction": "insert/update/delete/message/code",
        "moduleId": "",
        "appId": "",
        "appName": "工单中心",
        "appLogo": "",
        "selectObjName": "维保工单/编辑工单",
        "fieldOptions": {}
      }
    },
    {
      "id": "998",
      "uniqueId": "998",
      "options": {
        "apiId": "",
        "apiAction": "insert/update/delete/message/code",
        "moduleId": "",
        "appId": "",
        "appName": "工单中心",
        "appLogo": "",
        "selectObjName": "维保工单/编辑工单",
        "fieldOptions": {}
      }
    },
    {
      "id": "99810",
      "uniqueId": "99810",
      "options": {
        "apiId": "",
        "apiAction": "insert/update/delete/message/code",
        "moduleId": "",
        "appId": "",
        "appName": "工单中心99810",
        "appLogo": "",
        "selectObjName": "维保工单/编辑工单",
        "fieldOptions": {}
      }
    }
  ],
  "lineList": [
    {
      "id": '451222',
      "name": "条件名称",
      "from": "1222",
      "to": "12232",
      "options": {
        "convertType": "mapping/code",
        "convertCode": "",
        "conditionList": [
          [
          
          ]
        ]
      }
    },
    {
      "id": '451222',
      "name": "条件名称",
      "from": "12232",
      "to": "998",
      "options": {
        "convertType": "mapping/code",
        "convertCode": "",
        "conditionList": [
          [
          
          ]
        ]
      }
    },
    {
      "id": '451222',
      "name": "条件名称",
      "from": "998",
      "to": "99810",
      "options": {
        "convertType": "mapping/code",
        "convertCode": "",
        "conditionList": [
          [
          
          ]
        ]
      }
    },
  ]
} as unknown as TriggerFlowData

export const serverData2 = {
  "id": "触发器id",
  "name": "触发器名称",
  "executeWay": {
    "way": "event",
    "name": "事件触发",
    "options": {}
  },
  "startNode": {
    "id": "1222",
    "uniqueId": "1222",
    "options": {
      "apiId": "567",
      "apiAction": "select",
      "moduleId": "123",
      "appId": "987",
      "appName": "工单中心",
      "appLogo": "",
      "selectObjName": "维保工单/工单信息"
    }
  },
  "nodeList": [
    {
      "id": "12223",
      "uniqueId": "12223",
      "options": {
        "apiId": "",
        "apiAction": "insert/update/delete/message/code",
        "moduleId": "",
        "appId": "",
        "appName": "工单中心",
        "appLogo": "",
        "selectObjName": "维保工单/编辑工单",
        "fieldOptions": {}
      }
    }
  ],
  "lineList": [
    {
      "id": 456,
      "name": "条件名称",
      "from": "startNodeUniqueId",
      "to": "toNodeUniqueId",
      "options": {
        "convertType": "mapping/code",
        "convertCode": "",
        "conditionList": [
          [
            {
              "value": [
                "15899999999"
              ],
              "operate": "NOT_EQ",
              "toEnName": "fbd0a248-f089-4664-8063-a41c22a5eb5f:field_4CXOdB9URxML7fYz",
              "valueType": 1
            },
            {
              "value": [
                "15800000000"
              ],
              "operate": "NOT_EQ",
              "toEnName": "fbd0a248-f089-4664-8063-a41c22a5eb5f:field_4CXOdB9URxML7fYz",
              "valueType": 1
            }
          ]
        ]
      }
    }
  ]
} as unknown as TriggerFlowData

export const serverData3 = {

  "id": "RHPy3BCro9t7BxJ987dUHB",

  "name": "绿桶复杂触发器",

  "executeWay": {

    "way": "event",

    "name": "事件触发",

    "options": {

      "actionList": [

        "TASK_CREATE",

        "TASK_START"

      ]

    }

  },

  "startNode": {

    "id": "11565",

    "uniqueId": "11565",

    "options": {

      "apiId": "4zYzje6mi7so7z6k7Q95Vs7DchPNnFYN4xEYHykAE68t4sFLKEtibnSCFL5Nt5TpzwW22",

      "apiAction": "SELECT",

      "moduleId": "2d4372ee-59a6-45c7-9e24-4b0b7edf222b",

      "appId": "asJkbTJyVJivkKkddNKf5fKZ8JA2",

      "appName": "工单中心",

      "appLogo": "icon-creditcard-fill",

      "selectObjName": "九华工单",

      "fieldOptions": null

    }

  },

  "nodeList": [

    {

      "id": "11566",

      "uniqueId": "11566",

      "options": {

        "apiId": "ErMKcuU9x3PTfydAeh6w53SeoaggdB1ekAfMFcnDeyTCJ7bdPdribnSCFL5Nt5TpzwW22",

        "apiAction": "DELETE",

        "moduleId": "24f9ec17-5bf9-4a5b-b27c-196228e40350",

        "appId": "asJkbTJyVJivkKkddNKf5fKZ8JA2",

        "appName": "工单中心",

        "appLogo": "icon-creditcard-fill",

        "selectObjName": "既此测试多节点/删除数据",

        "fieldOptions": {

          "message": {

            "paasReceiver": "[{\"id\":\"24f9ec17-5bf9-4a5b-b27c-196228e40350:createUser\",\"name\":\"既此测试多节点:创建人\",\"type\":\"6\"}]",

            "displayTypeList": []

          },

          "delete": [

            {

              "toEnName": "customer",

              "valueType": "2",

              "value": [

                "2d4372ee-59a6-45c7-9e24-4b0b7edf222b:customer"

              ],

              "operate": "EQ"

            }

          ]

        }

      }

    },

    {

      "id": "11567",

      "uniqueId": "11567",

      "options": {

        "apiId": "message",

        "apiAction": "message",

        "moduleId": null,

        "appId": null,

        "appName": null,

        "appLogo": null,

        "selectObjName": null,

        "fieldOptions": {

          "side": 0,

          "sendTargetParam": {

            "userTypeList": [],

            "paasReceiver": "[{\"id\":\"06af7cdc-3e2c-11ed-8999-00163f00409a\",\"name\":\"阿呆\",\"type\":1}]"

          },

          "callingTemplateParam": {

            "typeName": "trigger_11567",

            "blockCallConfig": 0,

            "continuedCalls": 1,

            "id": 400,

            "content": "您好，您有一个{applicationName}有更新，请及时处理"

          },

          "configId": 13166,

          "sendChannelList": [

            "1"

          ],

          "smsTemplateParam": {

            "applyContent": "触发器",

            "name": "trigger_11567",

            "id": 26516,

            "notice": "trigger_11567（内部）"

          },

          "paasConfigName": "trigger_11567",

          "tenantId": "85c4d9182a09b612adb57957ffeb736f",

          "systemTemplateParam": {

            "sysContent": "内容",

            "displayTypeList": [

              "1"

            ],

            "id": 218316,

            "sysTitle": "正文标题",

            "sysDisplayFieldCheckMap": [

              {

                "defaultValue": "xxxxx",

                "check": true,

                "value": "九华工单:附件",

                "key": "2d4372ee-59a6-45c7-9e24-4b0b7edf222b:attachment",

                "canCancel": true

              }

            ],

            "sysDetailDisplayFieldCheckMap": null

          },

          "emailMsgTemplateParam": {

            "ccType": [

              1

            ],

            "subjectLanguage": null,

            "attachment": [],

            "receiverType": [],

            "subject": "消息提醒",

            "tenantId": null,

            "typeName": "trigger_11567",

            "contentLanguage": {},

            "messageId": 218317,

            "content": "【售后宝】您有一个申请单据（编号：{serialNumber}）需要尽快完成{CURRENT_NODE}节点的处理，以免延误进度。"

          },

          "notifyConfig": {

            "mode": "once",

            "endConfig": {

              "mode": null,

              "number": null,

              "fieldName": null,

              "onTheHour": null,

              "dataType": null,

              "dateStatus": null

            },

            "timeType": "now",

            "startConfig": {

              "mode": null,

              "number": null,

              "fieldName": null,

              "onTheHour": null,

              "dataType": null,

              "dateStatus": null

            },

            "strategyConfig": {

              "onTheHour": null,

              "nums": null,

              "strategyType": null

            }

          }

        }

      }

    },

    {

      "id": "11568",

      "uniqueId": "11568",

      "options": {

        "apiId": "mdBrUnfUUgCoZYSsFZLyk9aJFG",

        "apiAction": "INSERT",

        "moduleId": "52XF4kooFQHLrUTXQEBKCBdFC472cP",

        "appId": "nQrKZpSk9Mk9tnDChU68a5MfMc286",

        "appName": "金蝶云星空",

        "appLogo": "https://shb-multi.oss-cn-hangzhou.aliyuncs.com/images/logo/app/jindie.png",

        "selectObjName": "单据管理/新增其他入库单",

        "fieldOptions": {

          "convertType": "mapping",

          "insert": [

            {

              "toEnName": "FBillNo",

              "valueType": "2",

              "value": [

                "2d4372ee-59a6-45c7-9e24-4b0b7edf222b:description"

              ]

            },

            {

              "toEnName": "F_Yeo_Text_kh",

              "valueType": "2",

              "value": [

                ""

              ]

            },

            {

              "toEnName": "FEntity",

              "valueType": "2",

              "value": [

                "{\"triggerSubform\":1,\"fromEnName\":\"\",\"relationShip\":{\"FMATERIALID.FNumber\":{\"value\":\"\",\"valueType\":2},\"FSTOCKID.FNumber\":{\"value\":\"\",\"valueType\":2},\"FUnitID.FNumber\":{\"value\":\"\",\"valueType\":2},\"FQty\":{\"value\":\"\",\"valueType\":2},\"FPRODUCEDATE\":{\"value\":\"\",\"valueType\":2},\"FSTOCKSTATUSID.FNumber\":{\"value\":\"\",\"valueType\":2},\"FOWNERTYPEID\":{\"value\":\"\",\"valueType\":2},\"FOWNERID.FNumber\":{\"value\":\"\",\"valueType\":2},\"FKEEPERTYPEID\":{\"value\":\"\",\"valueType\":2},\"FLOT.FNumber\":{\"value\":\"\",\"valueType\":2},\"FEntryNote\":{\"value\":\"\",\"valueType\":2},\"F_YEO_DECIMAL_JSHJ\":{\"value\":\"\",\"valueType\":2},\"F_Yeo_Text_dddhr\":{\"value\":\"\",\"valueType\":2},\"F_Yeo_Text_ysdh\":{\"value\":\"\",\"valueType\":2}}}"

              ]

            }

          ]

        }

      }

    },

    {

      "id": "11569",

      "uniqueId": "11569",

      "options": {

        "apiId": "code",

        "apiAction": "code",

        "moduleId": null,

        "appId": null,

        "appName": null,

        "appLogo": null,

        "selectObjName": null,

        "fieldOptions": {

          "code": "package cn.publink.shb.application.facade.controller.connector.outside;\n\nimport cn.publink.shb.application.service.common.service.ShbExecuteCodeService;\nimport com.alibaba.fastjson.JSONObject;\nimport org.slf4j.Logger;\nimport org.slf4j.LoggerFactory;\n\n/**\n * 执行代码的示例\n * 1.fromObject为前置节点的业务数据，例如某工单表单数据，某客户表单数据\n * 数据结构为typeId:fieldName。例如某工单的类型typeId=bdf4d1c4-8d1f-458e-b4fc-24835499329e，fromData数据如下\n * {\n *   \"bdf4d1c4-8d1f-458e-b4fc-24835499329e:taskNo\": \"TAQ125024030520\",\n *   \"bdf4d1c4-8d1f-458e-b4fc-24835499329e:customer\": {\n *     \"serialNumber\": \"zmjjkk\",\n *     \"name\": \"zmjjkk\",\n *     \"id\": \"9ea625a6-eb22-11ee-8999-00163f00409a\"\n *   },\n *   \"bdf4d1c4-8d1f-458e-b4fc-24835499329e:templateId\": \"bdf4d1c4-8d1f-458e-b4fc-24835499329e\",\n *   \"bdf4d1c4-8d1f-458e-b4fc-24835499329e:createTime\": \"2024-03-28 14:47:01\"\n * }\n *\n * 2.最后返回的JSONObject会作为参数流转到下个节点，后续节点可拿到JSONObject的数据,如果不需要返回数据，直接返回null即可\n * 3.可以通过@Autowired注入spring容器中的bean\n * 详细说明查看文档：https://www.yuque.com/shb/help2/ox8c8k8i3hp1g6do#N8WYr\n */\npublic class ShbExecuteCodeDemo implements ShbExecuteCodeService {\n\n  private final static Logger log = LoggerFactory.getLogger(\"ShbExecuteCodeDemo\");\n\n  @Override\n  public JSONObject execute(JSONObject fromObject) {\n    //do something ,执行需要的逻辑\n    return null;\n  }\n}\n",

          "title": "123"

        }

      }

    },

    {

      "id": "11570",

      "uniqueId": "11570",

      "options": {

        "apiId": "oB3S2BCro9t7BxJ987dUHB",

        "apiAction": "UPDATE",

        "moduleId": null,

        "appId": "csJkbTJyVJivkKkddNKf5fKZ8JA2",

        "appName": "客户管理",

        "appLogo": "icon-creditcard-fill",

        "selectObjName": "客户表单/编辑数据",

        "fieldOptions": {

          "select": [

            {

              "toEnName": "serialNumber",

              "valueType": "2",

              "value": [

                "2d4372ee-59a6-45c7-9e24-4b0b7edf222b:description"

              ],

              "operate": "CONTAINS"

            }

          ],

          "update": [

            {

              "toEnName": "field_Ot6R9aAioGtQVMC8",

              "valueType": "2",

              "value": [

                "2d4372ee-59a6-45c7-9e24-4b0b7edf222b:description"

              ]

            }

          ]

        }

      }

    },

    {

      "id": "11571",

      "uniqueId": "11571",

      "options": {

        "apiId": "code",

        "apiAction": "code",

        "moduleId": null,

        "appId": null,

        "appName": null,

        "appLogo": null,

        "selectObjName": null,

        "fieldOptions": {

          "code": "package cn.publink.shb.application.facade.controller.connector.outside;\n\nimport cn.publink.shb.application.service.common.service.ShbExecuteCodeService;\nimport com.alibaba.fastjson.JSONObject;\nimport org.slf4j.Logger;\nimport org.slf4j.LoggerFactory;\n\n/**\n * 执行代码的示例\n * 1.fromObject为前置节点的业务数据，例如某工单表单数据，某客户表单数据\n * 数据结构为typeId:fieldName。例如某工单的类型typeId=bdf4d1c4-8d1f-458e-b4fc-24835499329e，fromData数据如下\n * {\n *   \"bdf4d1c4-8d1f-458e-b4fc-24835499329e:taskNo\": \"TAQ125024030520\",\n *   \"bdf4d1c4-8d1f-458e-b4fc-24835499329e:customer\": {\n *     \"serialNumber\": \"zmjjkk\",\n *     \"name\": \"zmjjkk\",\n *     \"id\": \"9ea625a6-eb22-11ee-8999-00163f00409a\"\n *   },\n *   \"bdf4d1c4-8d1f-458e-b4fc-24835499329e:templateId\": \"bdf4d1c4-8d1f-458e-b4fc-24835499329e\",\n *   \"bdf4d1c4-8d1f-458e-b4fc-24835499329e:createTime\": \"2024-03-28 14:47:01\"\n * }\n *\n * 2.最后返回的JSONObject会作为参数流转到下个节点，后续节点可拿到JSONObject的数据,如果不需要返回数据，直接返回null即可\n * 3.可以通过@Autowired注入spring容器中的bean\n * 详细说明查看文档：https://www.yuque.com/shb/help2/ox8c8k8i3hp1g6do#N8WYr\n */\npublic class ShbExecuteCodeDemo implements ShbExecuteCodeService {\n\n  private final static Logger log = LoggerFactory.getLogger(\"ShbExecuteCodeDemo\");\n\n  @Override\n  public JSONObject execute(JSONObject fromObject) {\n    //do something ,执行需要的逻辑\n    return null;\n  }\n}\n",

          "title": "1231123"

        }

      }

    },

    {

      "id": "11572",

      "uniqueId": "11572",

      "options": {

        "apiId": "code",

        "apiAction": "code",

        "moduleId": null,

        "appId": null,

        "appName": null,

        "appLogo": null,

        "selectObjName": null,

        "fieldOptions": {

          "code": "我是代码123",

          "title": "我是代码123"

        }

      }

    }

  ],

  "lineList": [

    {

      "id": 8164,

      "name": "测试 1",

      "from": "11565",

      "to": "11566",

      "options": {

        "convertType": "mapping",

        "convertCode": null,

        "conditionList": []

      }

    },

    {

      "id": 8165,

      "name": "",

      "from": "11565",

      "to": "11567",

      "options": {

        "convertType": "mapping",

        "convertCode": null,

        "conditionList": []

      }

    },

    {

      "id": 8166,

      "name": "",

      "from": "11567",

      "to": "11568",

      "options": {

        "convertType": "mapping",

        "convertCode": null,

        "conditionList": []

      }

    },

    {

      "id": 8167,

      "name": "",

      "from": "11565",

      "to": "11569",

      "options": {

        "convertType": "mapping",

        "convertCode": null,

        "conditionList": []

      }

    },

    {

      "id": 8168,

      "name": "",

      "from": "11569",

      "to": "11570",

      "options": {

        "convertType": "mapping",

        "convertCode": null,

        "conditionList": []

      }

    },

    {

      "id": 8169,

      "name": "",

      "from": "11569",

      "to": "11571",

      "options": {

        "convertType": "mapping",

        "convertCode": null,

        "conditionList": []

      }

    },

    {

      "id": 8170,

      "name": "",

      "from": "11565",

      "to": "11572",

      "options": {

        "convertType": "mapping",

        "convertCode": null,

        "conditionList": []

      }

    }

  ]

} as unknown as TriggerFlowData

export const serverData4 = [{
  "type": "nodeStart",
  "name": "开始节点-jinkai",
  "content": "",
  "children": [
      {
          "type": "node",
          "name": "消息通知",
          "content": "",
          "children": [],
          "id": "",
          "uniqueId": "654e5d3f-dc9d-4aae-867d-dcaf17b6dc40",
          "options": {
              "type": "message",
              "requiredCheck": true,
              "apiId": "message",
              "fieldOptions": {
                  "sendChannelList": [
                      "1"
                  ],
                  "sendTargetParam": {
                      "userTypeList": [],
                      "sendTargetPartList": [
                          {
                              "id": "393429378dfd74d22143f2c6bf6e1fae",
                              "type": 1,
                              "staffId": "0223656148631178174",
                              "name": "金凯"
                          }
                      ],
                      "paasReceiver": "[{\"id\":\"393429378dfd74d22143f2c6bf6e1fae\",\"type\":1,\"staffId\":\"0223656148631178174\",\"name\":\"金凯\"}]"
                  },
                  "notifyConfig": {
                      "mode": "once",
                      "timeType": "now",
                      "startConfig": {},
                      "endConfig": {},
                      "strategyConfig": {}
                  },
                  "configId": 14028,
                  "paasConfigName": 14028,
                  "side": 0,
                  "systemTemplateParam": {
                      "sysDisplayFieldCheckMap": [
                          {
                              "canCancel": true,
                              "check": true,
                              "defaultValue": "xxxxx",
                              "key": "afd97094-5487-4f16-9c7e-aa6205165956:attachment",
                              "value": "新版-智能机器人-凯风:附件"
                          }
                      ],
                      "displayTypeList": [
                          "1"
                      ],
                      "sysTitle": "正文标题",
                      "sysContent": "内容",
                      "id": 220552
                  },
                  "smsTemplateParam": {
                      "id": 27354,
                      "applyContent": "触发器",
                      "name": null,
                      "notice": "连接器公用模板(客户)"
                  },
                  "emailMsgTemplateParam": {
                      "messageId": 220553,
                      "typeName": "triggerEmailPublicTemplate",
                      "receiverType": [],
                      "ccType": [
                          1
                      ],
                      "subject": "消息提醒",
                      "subjectLanguage": null,
                      "attachment": [],
                      "content": "【售后宝】您有一个申请单据（编号：{serialNumber}）需要尽快完成{CURRENT_NODE}节点的处理，以免延误进度。",
                      "contentLanguage": {}
                  },
                  "tenantConfig": {
                      "configId": 14028,
                      "userTypeList": [],
                      "sendTargets": {
                          "userTypeList": null,
                          "sendTargetPartList": null,
                          "paasReceiver": null
                      },
                      "sendChannels": {
                          "avaliableList": [
                              "1"
                          ],
                          "sendChannelDescriptions": [
                              {
                                  "channel": "1",
                                  "channelType": "sysMsg",
                                  "channelTypeDescription": "系统消息"
                              },
                              {
                                  "channel": "2",
                                  "channelType": "smsMsg",
                                  "channelTypeDescription": "短信消息"
                              },
                              {
                                  "channel": "3",
                                  "channelType": "emailMsg",
                                  "channelTypeDescription": "邮件消息"
                              },
                              {
                                  "channel": "5",
                                  "channelType": "call",
                                  "channelTypeDescription": "电话消息"
                              }
                          ],
                          "outsideSendChannelDescriptions": [
                              {
                                  "channel": "2",
                                  "channelType": "smsMsg",
                                  "channelTypeDescription": "短信消息"
                              },
                              {
                                  "channel": "3",
                                  "channelType": "emailMsg",
                                  "channelTypeDescription": "邮件消息"
                              }
                          ]
                      },
                      "applyRangeList": [],
                      "taskPlanTime": null,
                      "systemTemplate": null,
                      "smsTemplate": null,
                      "emailTemplate": null,
                      "wechatTemplate": null,
                      "isEmailSetUp": true,
                      "side": 1,
                      "isWechatOfficialSetUp": true
                  },
                  "channelList": [
                      {
                          "channel": "1",
                          "channelType": "sysMsg",
                          "channelTypeDescription": "系统消息"
                      },
                      {
                          "channel": "2",
                          "channelType": "smsMsg",
                          "channelTypeDescription": "短信消息"
                      },
                      {
                          "channel": "3",
                          "channelType": "emailMsg",
                          "channelTypeDescription": "邮件消息"
                      }
                  ],
                  "isEditMessage": true
              }
          },
          "parentNode": {
              "type": "nodeStart",
              "name": "开始节点-jinkai",
              "content": "",
              "uniqueId": "d342b5fc-f2cc-426d-8217-8ee1d715312b",
              "id": "",
              "options": {},
              "parentNode": null
          }
      }
  ],
  "uniqueId": "d342b5fc-f2cc-426d-8217-8ee1d715312b",
  "id": "",
  "options": {
      "appId": "asJkbTJyVJivkKkddNKf5fKZ8JA2",
      "appName": "工单中心",
      "appLogo": "icon-creditcard-fill",
      "moduleId": "afd97094-5487-4f16-9c7e-aa6205165956",
      "apiId": "WK9udTUncqairvqr3ifFt7oWeHGJKbpQarpW932RhFRLiXtqCZqqbnSCFL5Nt5TpzwW22",
      "selectObjName": "新版-智能机器人-凯风"
  },
  "parentNode": null
}]

export const serverData5 = {
  "id": "3kPy3BCro9t7BxJ987dUHB",
  "name": "测试名称显示问题-jinkai-发",
  "executeWay": {
      "way": "event",
      "name": "事件触发",
      "options": {
          "actionList": [
              "TASK_CREATE"
          ]
      }
  },
  "startNode": {
      "id": "12145",
      "uniqueId": "12145",
      "name": "jinkai-fjaljflajfa",
      "options": {
          "apiId": "ad3ocbfa15HCR9kvPiwgTPMaL4rgsd4tSjSM9xiP7bbtcxJyg5TjbnSCFL5Nt5TpzwW22",
          "apiAction": "SELECT",
          "apiName": "工单新建",
          "moduleId": "68fe2743-96e7-4cdd-8a44-6b7bff968ca4",
          "appId": "asJkbTJyVJivkKkddNKf5fKZ8JA2",
          "appName": "工单中心",
          "appLogo": "icon-creditcard-fill",
          "selectObjName": "林子复制表单企鹅版pro",
          "fieldOptions": null
      }
  },
  "nodeList": [
      {
          "id": "12146",
          "uniqueId": "12146",
          "name": 'jinkai-nodelist',
          "options": {
              "apiId": "message",
              "apiAction": "message",
              "apiName": null,
              "moduleId": null,
              "appId": null,
              "appName": null,
              "appLogo": null,
              "selectObjName": null,
              "fieldOptions": {
                  "side": 0,
                  "sendTargetParam": {
                      "userTypeList": [],
                      "paasReceiver": "[{\"id\":\"393429378dfd74d22143f2c6bf6e1fae\",\"name\":\"金凯\",\"type\":1}]"
                  },
                  "callingTemplateParam": null,
                  "configId": 14041,
                  "sendChannelList": [
                      "1"
                  ],
                  "smsTemplateParam": {
                      "applyContent": "触发器",
                      "name": "trigger_12146",
                      "id": 27367,
                      "notice": "trigger_12146（内部）"
                  },
                  "paasConfigName": "trigger_12146",
                  "tenantId": "85c4d9182a09b612adb57957ffeb736f",
                  "systemTemplateParam": {
                      "sysContent": "内容",
                      "displayTypeList": [
                          "1"
                      ],
                      "id": 220585,
                      "sysTitle": "正文标题",
                      "sysDisplayFieldCheckMap": [
                          {
                              "defaultValue": "xxxxx",
                              "check": true,
                              "value": "林子复制表单企鹅版pro:附件",
                              "key": "68fe2743-96e7-4cdd-8a44-6b7bff968ca4:attachment",
                              "canCancel": true
                          }
                      ],
                      "sysDetailDisplayFieldCheckMap": null
                  },
                  "emailMsgTemplateParam": {
                      "ccType": [
                          1
                      ],
                      "subjectLanguage": null,
                      "attachment": [],
                      "receiverType": [],
                      "subject": "消息提醒",
                      "tenantId": null,
                      "typeName": "trigger_12146",
                      "contentLanguage": {},
                      "messageId": 220586,
                      "content": "【售后宝】您有一个申请单据（编号：{serialNumber}）需要尽快完成{CURRENT_NODE}节点的处理，以免延误进度。"
                  },
                  "notifyConfig": {
                      "mode": "once",
                      "endConfig": {
                          "mode": null,
                          "number": null,
                          "fieldName": null,
                          "onTheHour": null,
                          "dataType": null,
                          "dateStatus": null
                      },
                      "timeType": "now",
                      "startConfig": {
                          "mode": null,
                          "number": null,
                          "fieldName": null,
                          "onTheHour": null,
                          "dataType": null,
                          "dateStatus": null
                      },
                      "strategyConfig": {
                          "onTheHour": null,
                          "nums": null,
                          "strategyType": null
                      }
                  }
              }
          }
      }
  ],
  "lineList": [
      {
          "id": 8504,
          "name": null,
          "from": "12145",
          "to": "12146",
          "options": {
              "convertType": "mapping",
              "convertCode": null,
              "conditionList": null
          }
      }
  ]
}

/**
 * @desc 判断是否有条件 当conditionList或者convertCode有值情况也就是不等于 null 的情况
 * @param edge 
 */
const checkedHasCondition = (edge:TriggerEdge)=> {
  if(Reflect.has(edge.options, 'conditionList') && edge.options.conditionList){
    return true
  }
  if(Reflect.has(edge.options, 'convertCode') && edge.options.convertCode){
    return true
  }
  return false
}

/**
 * @desc 相关服务端数据转为前端流程渲染的数据
 * @param {any} data:TriggerFlowData=serverData
 * @returns {any}
 */
export const convertServerDataForProcessCanvas = (data: TriggerFlowData) => {
    const { startNode, executeWay, nodeList: defaultNodeList, lineList } = data

    if (!startNode.options) startNode.options = {}
    startNode.options.executeWay = executeWay
    startNode.type = NodeTypeEnum.START_NODE

    // 合并相关开始节点到nodeList中并且转为前端渲染的流程图的相关node数据结构
    const allProcessNodeNodeList = [startNode, ...defaultNodeList].map(node=> new ProcessNode(node))

    // 是否在子流程中处理过的节点
    const hadProcessNodeSet = new Set(); 


    /**
     * @desc 生成相关父节点
     * @param {any} node:ProcessNode
     * @returns {any}
     */
    const genParentDataNode = (node: ProcessNode)=> {
        const clonedNode = _.cloneDeep(node)
        clonedNode.parentNode = null
        clonedNode.children = []
        return clonedNode
    } 


    /**
     * @des 相关循环所有的节点列表
     * @param {any} nodeList:ProcessNode[]
     * @returns {any}
     */
    const traverseNode = (nodeList: ProcessNode [])=> {
        const resultNode: ProcessNode[] = []

        for(let i = 0; i< nodeList.length; i++) {
            const node = nodeList[i]

            // 根据当前的node的id去找对应的连接它的线 并且有条件数据
            const formFilterEdges = lineList.filter((edge: TriggerEdge) => {
              return edge?.from === node.id && checkedHasCondition(edge)
            });

            if(formFilterEdges.length > 0) {
              // 生成条件节点的占位节点也就是 type 等于 condition
              const genProcessEdge = new ProcessEdge({})

              //赋值相关父节点
              genProcessEdge.parentNode = genParentDataNode(node)

              genProcessEdge.children = formFilterEdges.map((edge:TriggerEdge )=> {
                // 找到对应线的目标节点
                const edgeTargetNode = defaultNodeList.find(node => node.id === edge.to);

                // 不存在edgeTargetNode直接 return null
                if(!edgeTargetNode) return null

                const targetProcessNode = new ProcessNode(edgeTargetNode)
                // 判断是否有条件以及条件是否有值 生成对应的条件节点
                if(checkedHasCondition(edge)) {
                  // 生成条件节点
                  const conditionProcessNode = new ProcessNode({ 
                    id: edge.uniqueId || edge.id || undefined,
                    uniqueId: edge.uniqueId || edge.id || '', 
                    name: edge?.name || '',
                    type: NodeTypeEnum.CONDITION_NODE,
                    options: edge.options 
                  })

                  //赋值相关父节点
                  conditionProcessNode.parentNode = genParentDataNode(genProcessEdge)

                  // 找到线的目标节点 
                  if(edgeTargetNode.id) {
                    //赋值相关父节点
                    targetProcessNode.parentNode = genParentDataNode(conditionProcessNode)
                    
                    //条件节点下加入对应的普通节点
                    conditionProcessNode.children.push(targetProcessNode)
                    hadProcessNodeSet.add(targetProcessNode.id)
                    // 目标节点递归查找
                    traverseNode([targetProcessNode])
                  }

                  return conditionProcessNode
                }
                // 返回处理过后的前端渲染的需要的节点结构
                return targetProcessNode
         
              }).filter(Boolean) as unknown as ProcessNode []

              node.children.push(genProcessEdge)

            } else {
                // 找到对应线的目标节点
                const nodeLinkLines = lineList.filter(edge => edge.from === node.uniqueId);
                nodeLinkLines.forEach((nodeLinkLine)=> {
                    // 找到对应线的目标节点
                    const edgeTargetNode = defaultNodeList.find(node => node.id === nodeLinkLine.to);
                    if(edgeTargetNode) {
                        const targetProcessNode = new ProcessNode(edgeTargetNode)
                        //赋值相关父节点
                        targetProcessNode.parentNode = genParentDataNode(node)
                        node.children.push(targetProcessNode)
                        // 这里处理对应没有条件的节点
                        hadProcessNodeSet.add(targetProcessNode.id)
                        // 目标节点递归查找
                        traverseNode([targetProcessNode])
                    }
              })
            }

            if(!hadProcessNodeSet.has(node.id)) {
              resultNode.push(node)
            }  
        }
        return resultNode
    }
    return traverseNode(allProcessNodeNodeList)
}


/**
 * @desc 相关前端的流程数据转为后端接收的数据
 * @param {ProcessNod[]} dataList:ProcessNode[] // 前端流程图的数据结构
 * @param {TriggerFlowData} defaultTriggerFlowData:TriggerFlowData 默认的流程数据（后端返回）
 * @returns {TriggerFlowData}
 */
export const convertProcessCanvasDataForServer = ( dataList: ProcessNode [], defaultTriggerFlowData?: TriggerFlowData,): TriggerFlowData | null => {

  const nodeList: TriggerNode[] = []
  const lineList: TriggerEdge [] = []

  // 默认的线列表也就是后端返回的
  const defaultEdges: TriggerEdge [] = defaultTriggerFlowData?.lineList || []
 

  /**
   * @desc 判断条件是否是空的情况
   * @param {TriggerEdge} currentEdge:TriggerEdge
   * @returns {boolean}
   */
  const checkedIsHasCondition = (currentEdge: TriggerEdge): boolean=> {
    // 判断是否有conditionList并且是一个数组（可能是是 null 情况，所以判断是否是数组）
    if(Reflect.has(currentEdge.options, 'conditionList') && Array.isArray(currentEdge.options.conditionList)) {
      const conditionListLength = currentEdge.options.conditionList.length
      // 判断有可能条件conditionList的数据为 [[]]情况
      if(conditionListLength === 0 || (conditionListLength && currentEdge.options.conditionList[0]?.length === 0)) return false
      return true
    }
    return false  
  }

  /**
   * @desc 相关拍平树结构
   * @param {any} dataList:ProcessNode[] 前端渲染的流程图数据结构
   * @param {any} parentNode:ProcessNode|undefined 父节点
   * @returns {any}
   */
  const flatDataList = (dataList: ProcessNode [], parentNode: ProcessNode | undefined)=> {
      for(let i = 0; i< dataList.length; i++) {
        const dataItem = dataList[i]
        // 判断是发是开始节点和普通节点
        if([NodeTypeEnum.START_NODE, NodeTypeEnum.NODE].includes(dataItem.type)) {
          nodeList.push(new TriggerNode(dataItem))
        }

        // 判断是否是条件节点（占位节点）
        if(parentNode?.type === NodeTypeEnum.CONDITION) {
          // 条件节点下的节点只能是触发节点
          if(dataItem.type === NodeTypeEnum.CONDITION_NODE && Array.isArray(dataItem.children) && dataItem.children.length) {
            const existEdge = defaultEdges.find(item=> item.to ===  dataItem.children[0].uniqueId)
            // 这里parentNode对应的是递归循环的一个节点有在TriggerFrontProcessNode上parentNode
            if(parentNode.parentNode) {
              const currentEdge = {
                name: dataItem.name,
                from: parentNode.parentNode.uniqueId, 
                to: dataItem.children[0].uniqueId, 
                uniqueId: dataItem.uniqueId, 
                options: dataItem.options
              }

              // 判断是有已经创建过的线
              if(existEdge) {
                // 判断存在的线的 form 是否是 from 节点
                if(parentNode.parentNode.uniqueId !== existEdge?.from) {
                  existEdge.from =  parentNode.parentNode.uniqueId
                  if (checkedHasCondition(existEdge)) {
                    existEdge.options = {}
                  }
                }
                existEdge.options = dataItem.options
                existEdge.name = dataItem.name
              }

              lineList.push(new TriggerEdge( existEdge ? existEdge : currentEdge))
            }
          }
        }

        // 判断是否有子集
        if(Array.isArray(dataItem.children) && dataItem.children.length) {
          const childFirstNode = dataItem.children[0]
          // 判断他的子的第一个节点是否是 node 类型 以及当前循环的节点不是条件节点以及条件组节点
          if(childFirstNode.type === NodeTypeEnum.NODE && ![NodeTypeEnum.CONDITION_NODE, NodeTypeEnum.CONDITION].includes(dataItem.type)) {
            const existEdge = defaultEdges.find(item=> item.to === childFirstNode.uniqueId)
            const currentEdge = { 
              from: dataItem.uniqueId, 
              to: dataItem.children[0].uniqueId,
              uniqueId: dataItem.uniqueId, 
              options: {} 
            }
            // 判断存在的线的 form 是否是 from 节点
            if(existEdge && dataItem.uniqueId !== existEdge?.from) {
              existEdge.from =  dataItem.uniqueId
              if (checkedHasCondition(existEdge)) {
                existEdge.options = {}
              }
            }
            // 判断是有已经创建过的线
            lineList.push(new TriggerEdge( existEdge ? existEdge : currentEdge))
          }

          flatDataList(dataItem.children, dataItem)
        }
      }
  }

  flatDataList(dataList, undefined)

  if(nodeList.length) {

    const startNode = nodeList.shift() as unknown as TriggerNode

    return {
      name: defaultTriggerFlowData?.name || '',
      id: defaultTriggerFlowData?.id,
      executeWay: startNode?.options?.executeWay || {},
      startNode: startNode,
      lineList,
      nodeList
    }

  }
  return null
}